package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.Size;
import cn.stylefeng.guns.modular.system.model.params.SizeParam;
import cn.stylefeng.guns.modular.system.service.SizeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 货运尺码控制器
 *
 * @author ZhangJun
 * @Date 2019-07-05 14:35:57
 */
@Controller
@RequestMapping("/size")
public class SizeController extends BaseController {

    private String PREFIX = "/size";

    @Autowired
    private SizeService sizeService;

    /**
     * 跳转到主页面
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/size.html";
    }

    /**
     * 新增页面
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/size_add.html";
    }

    /**
     * 编辑页面
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/size_edit.html";
    }

    /**
     * 新增接口
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SizeParam sizeParam) {
        this.sizeService.add(sizeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SizeParam sizeParam) {
        this.sizeService.update(sizeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SizeParam sizeParam) {
        this.sizeService.delete(sizeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SizeParam sizeParam) {
        Size detail = this.sizeService.getById(sizeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author ZhangJun
     * @Date 2019-07-05
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(SizeParam sizeParam) {
        return this.sizeService.findPageBySpec(sizeParam);
    }

}


